#ifndef _MANAGED_ISTREAM_H_
#define _MANAGED_ISTREAM_H_

#include <ObjIdl.h>

using namespace System::IO;

ref class ManagedIStream : public Stream
{
public:
	ManagedIStream(IStream* stream, FileAccess accessMode) : _AccessMode(accessMode), _IStream(stream){}
	!ManagedIStream();
	~ManagedIStream();
	virtual property bool CanRead { bool get() override { return ((_AccessMode & FileAccess::Read) == FileAccess::Read); }; }
	virtual property bool CanSeek { bool get() override { return true; }; }
	virtual property bool CanWrite { bool get() override { return ((_AccessMode & FileAccess::Write) == FileAccess::Write); }; }
	virtual void Flush() override;
	virtual property INT64 Length { INT64 get() override; }
	virtual property INT64 Position { INT64 get() override; void set(INT64 value) override; }
	virtual int Read(array<byte>^ buffer, int offset, int count) override;
	virtual INT64 Seek(INT64 offset, SeekOrigin origin) override;
	virtual void SetLength(INT64 length) override;
	virtual void Write(array<byte>^ buffer, int offset, int count) override;
private:
	initonly FileAccess _AccessMode;
	IStream* _IStream;
};

#endif
